package models

type SystemQuestionKnowledge struct {
	Id           int `json:"id" xorm:"not null pk autoincr comment('主键') INT(11)"`
	QuestionId int `json:"question_id" xorm:"not null comment('题目主键') INT(11)"`
	KnowledgeId int `json:"knowledge_id" xorm:"not null comment('知识点主键')  INT(11)"`
}
var systemquestionknowledge ="system_question_knowledge"

func(q *SystemQuestionKnowledge) GetRow() bool {
	has, err := mEngine.Get(q)
	if err==nil &&  has  {
		return true
	}
	return false
}
//通过questionId,查询对应的knowledgeId
func(q *SystemQuestionKnowledge) GetByQuestionId(questionId int ) ([]int,error){
	var knowledgeIds []int
	err:=mEngine.Table(systemquestionknowledge).Cols("knowledge_id").
		Where("question_id =?  " ,questionId).Find(&knowledgeIds)


	return knowledgeIds, err


}

func(q *SystemQuestionKnowledge) DeleteByQuestionId(questionId int ) error{
	//No commitment
	_,err:=mEngine.Table(systemquestionknowledge).Where("question_id =?  " ,questionId).Delete(q)

	return  err

}
